package com.ruoyi.business.iService.impl;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.ruoyi.business.domain.entity.TbProduct;
import com.ruoyi.business.iService.ITbProductService;
import com.ruoyi.business.mapper.TbProductMapper;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品Service业务层处理
 *
 * @author ruoyi
 * @date 2025-07-26
 */
@Service
public class TbProductServiceImpl extends ServiceImpl<TbProductMapper, TbProduct> implements ITbProductService {

    /**
     * 查询商品列表
     *
     * @param tbProduct 商品
     * @return 商品
     */
    @Override
    public List<TbProduct> selectTbProductList(TbProduct tbProduct) {
        QueryWrapper queryWrapper = buildQuery(tbProduct);
        return mapper.selectListByQuery(queryWrapper);
    }

    /**
     * 查询商品列表
     *
     * @param tbProduct 商品
     * @return 商品
     */
    @Override
    public TableDataInfo selectTbProductPage(TbProduct tbProduct, PageDomain pageDomain) {
        QueryWrapper queryWrapper = buildQuery(tbProduct);
        Page<TbProduct> page = super.page(new Page<>(pageDomain.getPageNum(), pageDomain.getPageSize()), queryWrapper);
        return TableDataInfo.build(page);
    }

    private QueryWrapper buildQuery(TbProduct tbProduct) {
        QueryWrapper queryWrapper = query();
        queryWrapper.eq(TbProduct::getProductId, tbProduct.getProductId(), tbProduct.getProductId() != null);
        return queryWrapper;
    }

}
